package com.zht.service.impl;

import com.alibaba.excel.EasyExcel;
import com.zht.entity.CliqueSdWan;
import com.zht.entity.CliqueSdWanDto;
import com.zht.entity.InternetLineDto;
import com.zht.mapper.SelectSpeedListMapper;
import com.zht.service.SelectSpeedList;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@Service
public class SelectSpeedListImpl implements SelectSpeedList {

    @Autowired
    private SelectSpeedListMapper selectSpeedListMapper;

    @Override
    public List<String> getSpeedList() {
        // 获取速率集合
        List<String> stringList = selectSpeedListMapper.getSpeedList();
        return stringList;
    }

    @Override
    public Integer getExpenseBySpeed(String speed) {
        // 根据速率获取服务费
        Integer expense = selectSpeedListMapper.getExpenseBySpeed(speed);
        return expense;
    }

    /**
     * 上传excel表数据
     * @param file
     */
    @Override
    @Transactional
    public void uploadExcel(String uplink, MultipartFile file) throws IOException {
        List<CliqueSdWanDto> dataList = EasyExcel.read(file.getInputStream()).head(CliqueSdWanDto.class).sheet().doReadSync();
        // 删除数据
        selectSpeedListMapper.deleteData();
        // 新增新的数据
        selectSpeedListMapper.addData("1",uplink,dataList);

    }

    @Override
    public List<CliqueSdWan> selectDepartInfoList(CliqueSdWan cliqueSdWan) {
        List<CliqueSdWan> cliqueSdWans = selectSpeedListMapper.selectDepartInfoList(cliqueSdWan);
        return cliqueSdWans;
    }

    /**
     * 查询execl数据
     * @return
     */
    @Override
    public List<CliqueSdWan> list() {
        List<CliqueSdWan> list = selectSpeedListMapper.list();
        return list;
    }

    @Override
    public List<CliqueSdWan> selectCaononNumList(CliqueSdWan cliqueSdWan) {
        List<CliqueSdWan> cliqueSdWans = selectSpeedListMapper.selectCaononNumList(cliqueSdWan);
        return cliqueSdWans;
    }

    /**
     * 查询普通接入数据
     * @return
     */
    @Override
    public List<String> getNormalListList() {
       return selectSpeedListMapper.getNormalListList();
    }

    /**
     * 查询速率数据
     * @return
     */
    @Override
    public List<String> getSpeedListList() {
        return selectSpeedListMapper.getSpeedListList();
    }

    /**
     * 查询接入方式数据
     * @return
     */
    @Override
    public List<String> getAccessModeListList() {
        return selectSpeedListMapper.getAccessModeListList();
    }

    /**
     * 查询接入层级数据
     * @return
     */
    @Override
    public List<String> getAccessLevelListList() {
        return selectSpeedListMapper.getAccessLevelListList();
    }

    /**
     * 互联网-excel上传导入
     * @param file
     * @param uplink
     */
    @Override
    @Transactional
    public void uploadInternet(MultipartFile file, String uplink) throws IOException {
        List<InternetLineDto> dataList = EasyExcel.read(file.getInputStream()).head(InternetLineDto.class).sheet().doReadSync();
        // 删除数据
        selectSpeedListMapper.deleteInternetData();
        // 新增新的数据
        selectSpeedListMapper.addInternetData("1",uplink,dataList);
    }

}
